package com.mylife.schedule.controller;

import com.mylife.pojo.Result;
import com.mylife.schedule.service.ScheduleService;
import com.mylife.schedule.vo.NowScheduleVO;
import com.mylife.schedule.vo.params.ScheduleParams;
import com.mylife.schedule.vo.ScheduleVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 计划本controller
 *
 * @author blueCat
 * @since 2022/3/5
 */
@RestController
@RequestMapping("/mylife/schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    /**
     * 查询正在进行的计划
     * @param params
     * @return
     */
    @PostMapping("/queryNowSchedule")
    private NowScheduleVO queryNowSchedule(@RequestBody ScheduleParams params) {
        NowScheduleVO nowScheduleVO = scheduleService.queryNowSchedule(params);
        return nowScheduleVO;
    }

    /**
     * 查询全部计划类型
     * @return
     */
    @PostMapping("/queryScheduleType")
    public List<String> queryScheduleType(){
        return scheduleService.queryScheduleType();
    }

    /**
     * 新增计划
     * @param params
     * @return
     */
    @PostMapping("/addSchedule")
    public Result addSchedule(@RequestBody ScheduleParams params){
        return scheduleService.addSchedule(params);
    }

    /**
     * 查询计划
     * @param params
     * @return
     */
    @PostMapping("/querySchedules")
    public List<ScheduleVo> querySchedules(@RequestBody ScheduleParams params){
        return scheduleService.querySchedules(params);
    }

    /**
     * 删除任务
     * @param params
     * @return
     */
    @PostMapping("/deleteSchedule")
    public Result deleteSchedule(@RequestBody ScheduleParams params){
        return scheduleService.deleteSchedule(params.getId());
    }

    /**
     * 改变完成状态
     * @param params
     * @return
     */
    @PostMapping("/changeFinishStatus")
    public Result changeFinishStatus(@RequestBody ScheduleParams params){
        return scheduleService.changeFinishStatus(params.getId(),params.getIsFinish());
    }

    /**
     * 查询单条计划
     * @param params
     * @return
     */
    @PostMapping("/queryOneSchedule")
    public ScheduleVo queryOneSchedule(@RequestBody ScheduleParams params){
        return scheduleService.queryOneSchedule(params.getId());
    }

    /**
     * 修改计划
     * @param params
     * @return
     */
    @PostMapping("/updateSchedule")
    public Result updateSchedule(@RequestBody ScheduleParams params){
        return scheduleService.updateSchedule(params);
    }

    /**
     * 增加计划类型
     * @param scheduleType
     * @return
     */
    @PostMapping("/addScheduleType")
    public Result addScheduleType(@RequestBody String scheduleType){
        return scheduleService.addScheduleType(scheduleType);
    }

    /**
     * 统计计划内容
     * @param params
     * @return
     */
    @PostMapping("/queryCountSchedule")
    public List<ScheduleVo> queryCountSchedule(@RequestBody ScheduleParams params){
        return scheduleService.queryCountSchedule(params);
    }
}
